﻿using Ceremony.API.Model;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Ceremony.API.Infrastructure.EntityConfigurations
{
    public class BobingUserEntityTypeConfiguration
        : IEntityTypeConfiguration<BobingUser>
    {
        public void Configure(EntityTypeBuilder<BobingUser> builder)
        {
            builder.ToTable("BobingUser");

            builder.HasKey(ci => ci.Id);

            builder.Property(ci => ci.Id)
               .UseHiLo("bobinguser_hilo")
               .IsRequired();

            builder.Property(cb => cb.UserName)
                .IsRequired(true)
                .HasMaxLength(100);
            builder.Property(cb => cb.AuthorizationCode)
               .IsRequired(true)
               .HasMaxLength(500);
            builder.Property(cb => cb.Times)
               .IsRequired(true)
               .HasMaxLength(100);
            builder.Property(cb => cb.CreateTime)
               .IsRequired(true);
            builder.Property(cb => cb.IsRemove)
                .IsRequired(true);
            //frogin key
            builder.HasMany(b => b.BobingPrizeResults)
            .WithOne()
            .HasForeignKey("UserId")
            .OnDelete(DeleteBehavior.Cascade);

            var navigation = builder.Metadata.FindNavigation(nameof(BobingUser.BobingPrizeResults));
            navigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
    }
}
